Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix table selector and resizer #1919

Merged
merged 11 commits into from
Jun 30, 2023

Conversation

Andres-CT98
Copy link
Contributor

@Andres-CT98 Andres-CT98 commented Jun 27, 2023

Description:

The Table selector and resizer are currently inserted on the document, thus putting them on a different container to the table they belong to. This creates issues in some scenarios such as when a dialog is created above the document with a high z-index. They also have a fixed position which causes issues in some scrolling scenarios, where they stayed fixed in place instead of moving or disappearing.

Fix

Changed the insertion point of where the squares are located. The Selector is inserted before the table and the Resizer after it. Also changed its position from fixed to absolute and made changes to the CSS.

Change

Fixed scenarios:

  • Squares no longer stick on screen when scrolling.
  • Squares are in the same context as the table, so they are never hidden under the editor or overlap outside of it.

Before:
image

After:
image

Warnings and implications

  • The same scroll scenario where the squares remained on screen still has issues after this change. Both operations are not functional, but it is a rare scenario to encounter.
  • The same issue exists form the table Inserters and cell resizers.

@Andres-CT98 Andres-CT98 marked this pull request as ready for review June 27, 2023 20:15
@@ -41,12 +47,13 @@ export default function createTableSelector(
div.id = TABLE_SELECTOR_ID;
div.style.width = `${TABLE_SELECTOR_LENGTH}px`;
div.style.height = `${TABLE_SELECTOR_LENGTH}px`;
document.body.appendChild(div);
table.insertAdjacentElement('beforebegin', div);
Copy link
Collaborator

@JiuqingSong JiuqingSong Jun 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is to insert the handle DIV into editor content, is that right? If an auto save happens while the resize handle is showing, it will be saved as part of the content

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it is ok to insert here. But we need to remove it when getContent() is called, by handling ExtractContentWithDomEvent event

@@ -85,6 +85,8 @@ export default class TableResize implements EditorPlugin {
case PluginEventType.ContentChanged:
case PluginEventType.Scroll:
case PluginEventType.ZoomChanged:
case PluginEventType.ExtractContentWithDom:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not what I mean. You need to handle extractContentWithDom event separately, it will pass you a DocumentFragment, and you just need to remove the selector from that fragment, but no need to remove it from current editor. (The passed-in fragment is a cloned DOM tree of editor, so operating on that tree won't imapct editor)

That means, we just don't want the table selector to be saved, but from current editor, it should still show. User's resizing action should not be interrupted by auto save.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can I test auto save?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To simulate an auto save, you can add code to call window.setTimeout() with a delayed time, say 10sec. And in the callback you can call editor.getContent(), which will trigger this event.

@@ -35,7 +35,7 @@ export default function createTableResizer(

div.style.width = `${TABLE_RESIZER_LENGTH}px`;
div.style.height = `${TABLE_RESIZER_LENGTH}px`;
document.body.appendChild(div);
table.insertAdjacentElement('afterend', div);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we also need to do the same change for other table resize helper elements? Actually there are 6:

  1. Whole table selector
  2. Whole table resizer (these 2 are visible as a gray square)
  3. horizontal resizer
  4. vertical resizer
  5. new column inserter (a circle with "+" sign when hover above a table)
  6. new row inserter (a circle with "+" sign when hover on left side (or right side when RTL) of a table)

3,4 are invisible, but it will change mouse cursor when hover
5,6 will be visible when hover.

I can see your change fixed 1 and 2, so we also need same fix for 3-6. And maybe we should have a unified function for all of them to reduce duplicated code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that but wanted to do that on a separate PR. I think a better approach would be to do something like Image Edit does, where the helpers are in in a span.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's ok to do it separately, and please open an issue to track it.

I think it should be fine to use a SPAN for all the resizer UI, although this seems like a larger change.

@Andres-CT98 Andres-CT98 merged commit 5be7a7d into master Jun 30, 2023
@Andres-CT98 Andres-CT98 deleted the u/acampostams/fix-table-selector-and-resizer branch June 30, 2023 00:33
JiuqingSong added a commit that referenced this pull request Jun 30, 2023
JiuqingSong added a commit that referenced this pull request Jun 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants